#include "EScreen.h"
#include "eCPP.h"

namespace engine
{

//------------------------------------------------------------
EScreen::EScreen(const string& sName, const EScreenDesc& desc) :
m_Material( NULL ),
m_pNode( NULL ),
m_Rect( true ),
ESceneObject( sName, m_Rect ),
EResource( desc.m_sBagroundFileName )
{
  initRect();
}

//------------------------------------------------------------
EScreen::~EScreen()
{
}

//------------------------------------------------------------
void EScreen::initRect()
{
  m_Rect.setCorners(-1.0, 1.0, 1.0, -1.0);
  
  // Render the background before everything else
  m_Rect.setRenderQueueGroup(RENDER_QUEUE_BACKGROUND);

  // Hacky, but we need to set the bounding box to something big
  // NOTE: If you are using Eihort, please see the note below on setting the bounding box
  m_Rect.setBoundingBox(AxisAlignedBox(-100000.f * Vector3::UNIT_SCALE, 100000.f * Vector3::UNIT_SCALE));
}

//------------------------------------------------------------
bool EScreen::load( )
{
  cTEST( EResource::load() );

  m_Material = MaterialManager::getSingleton().create(m_sName, "General");
  TextureUnitState* pState = m_Material->getTechnique(0)->getPass(0)->createTextureUnitState( m_sResourceName );
  cTEST( pState != NULL );
  m_Material->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
  m_Material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
  m_Material->getTechnique(0)->getPass(0)->setLightingEnabled(false);
  m_Rect.setMaterial( m_sName );

  return true;
}
//------------------------------------------------------------
bool EScreen::update(const EGameTime& time )
{
  return true;
}

//------------------------------------------------------------
bool EScreen::startGame()
{
  return true;
}

//------------------------------------------------------------
bool EScreen::endGame()
{
  return true;
}

//------------------------------------------------------------
bool EScreen::updateGame(const EGameTime& time )
{
  return true;
}

} // end namespace